package com.wfk.service.impl;

import com.wfk.entity.BankDetails;
import com.wfk.mapper.BankDetailsMapper;
import com.wfk.service.IBankDetailsService;
import com.wfk.utils.ResponseData;
import com.wfk.utils.ValidateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

import org.springframework.stereotype.Service;

/**
 * <p>
 * 银行卡绑定信息 服务实现类
 * </p>
 *
 * @since 2019-01-07
 */
@Service
public class BankDetailsServiceImpl extends ServiceImpl<BankDetailsMapper, BankDetails> implements IBankDetailsService {

	/**
	 * 
	 * 我的银行卡列表
	 * @param cid
	 * @return
	 */
	@Override
	public List<BankDetails> myBankDetail(Integer cid){
		QueryWrapper<BankDetails> queryWrapper = new QueryWrapper<BankDetails>();
		queryWrapper.eq("targetid",cid);
		queryWrapper.orderByDesc("id");
		List<BankDetails> list = super.list(queryWrapper);
		for(BankDetails bank:list) {
			if(ValidateUtil.empty(bank.getBankcode())&&bank.getBankcode().length()>4) {
				bank.setBankcode(bank.getBankcode().substring(bank.getBankcode().length()-4, bank.getBankcode().length()));
			}
		}
		return list;
	}
	/**
	 * 接触绑定
	 * @param cid
	 * @param id
	 * @return
	 */
	@Override
	public ResponseData devBankDetail(Integer cid,Integer id){
		QueryWrapper<BankDetails> queryWrapper = new QueryWrapper<BankDetails>();
		queryWrapper.eq("targetid", cid);
		queryWrapper.eq("id", id);
		boolean count = super.remove(queryWrapper);
		if(count){
			return ResponseData.ok("解绑成功");
		}
		return ResponseData.baseServiceError("系统繁忙，解绑失败");
	}
	
}
